﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using TrabalhoLAP.Model.Class;

namespace TrabalhoLAP.DAO
{
    public class AvaliacaoDAO
    {        
        public DataSet consultarCategoria(string areaConcentracao, double vlrAvaliacao, string statusRegistro)
        {
            AcessoBanco acess = new AcessoBanco();
            string sql;
            string sqlWhere = "";

            sql = "SELECT codAvaliacao, areaConcentracao, vlrAvaliacao, statusRegistro FROM AVALIACAO ";

            if (!areaConcentracao.Equals(""))
                sqlWhere = areaConcentracao.Equals("") ? "" : "WHERE areaConcentracao LIKE '%" + areaConcentracao + "%'";

            if (sqlWhere.Equals("") && !vlrAvaliacao.ToString().Equals(""))
                sqlWhere = vlrAvaliacao.Equals("") ? "" : "WHERE vlrAvaliacao = " + vlrAvaliacao;
            else if ((!sqlWhere.Equals("")) && (!vlrAvaliacao.Equals("")))
                sqlWhere = vlrAvaliacao.Equals("") ? "" : " AND vlrAvaliacao = " + vlrAvaliacao;

            if (sqlWhere.Equals(""))
                sqlWhere = "WHERE STATUSREGISTRO = '" + statusRegistro + "'";
            else
                sqlWhere += " AND STATUSREGISTRO = '" + statusRegistro + "'";

            sql = sql + sqlWhere;

            return acess.executeSelectQuery(sql);
        }

        public bool cadastrarAvaliacao(string areaConcentracao, double vlrAvaliacao, string statusRegistro)
        {
            AcessoBanco acess = new AcessoBanco();
            string sql;

            sql = "INSERT USUARIO (areaConcentracao, vlrAvaliacao, statusRegistro) VALUES('" + areaConcentracao + "'," + vlrAvaliacao + "'" + statusRegistro + "'";
            return acess.executeQuery(sql);
        }

        public bool alterarAvaliacao(int codAvaliacao, double areaConcentracao, int vlrAvaliacao, string statusRegistro)
        {
            AcessoBanco acess = new AcessoBanco();
            string sql;

            sql = "UPDATE USUARIO SET areaConcentracao = '" + areaConcentracao + "', vlrAvaliacao = " + vlrAvaliacao + "statusRegistro = '" + statusRegistro + "'";
            sql += " WHERE CODCATEGORIA = " + codAvaliacao;

            return acess.executeQuery(sql);
        }

    }
}